# coding:utf-8

import cv2
import numpy


def test1():
    srcimg = cv2.imread("0046.png", cv2.IMREAD_UNCHANGED)
    if srcimg is None:
        return
    if not isinstance(srcimg, numpy.ndarray):
        return

    print srcimg.shape
    print srcimg.size
    print srcimg.dtype

    srcimg[50, 1] = 65535
    srcimg[50, 2] = 65535
    srcimg[50, 3] = 65535
    srcimg[50, 4] = 65535
    srcimg[50, 5] = 65535

    cv2.imshow("srcimg", srcimg)
    cv2.waitKey(1)

    roiimg = srcimg[50:100, 0:100]
    assert isinstance(roiimg, numpy.ndarray)
    cv2.imshow("ROI", roiimg)
    cv2.waitKey(1)

    maskimg = numpy.zeros(srcimg.shape[0:2], dtype=numpy.uint8)
    maskimg[100:200, 200:300] = 255
    addimg = cv2.add(srcimg, srcimg, mask=maskimg)
    cv2.imshow("masked img", addimg)
    cv2.waitKey(1)

    retv, thresimg = cv2.threshold(srcimg.astype(numpy.uint8), 220, 255,
                                   cv2.THRESH_TOZERO)  # type: (float, numpy.ndarray)
    print thresimg.dtype
    cv2.imshow("threshold img", thresimg)
    cv2.waitKey(1)

    colorimg = cv2.cvtColor(srcimg, cv2.COLOR_GRAY2BGR)  # type: numpy.ndarray
    print colorimg.dtype
    print colorimg.shape
    colorimg[:, :, 0] = 0
    cv2.imshow("colorimg", colorimg)
    cv2.waitKey(1)

    resizeimg = cv2.resize(srcimg, (512, 512))  # type: numpy.ndarray
    cv2.imshow("resized img", resizeimg)
    cv2.waitKey(1)

    cv2.waitKey(0)


test1()
